package yxk.form.kd.wtc.wtpm.mob.supsignpc;/*
 *
 *@author lqh
 *@date 2023/9/15
 *
 */

import kd.bos.bill.AbstractMobBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.wtc.wtpm.business.sign.mobile.MobSupSignBusiness;

import java.util.Date;
import java.util.EventObject;
import java.util.Optional;

public class SupSignPCMobBillPlugin extends AbstractMobBillPlugIn {
    private final MobSupSignBusiness mobSupSignBusiness = MobSupSignBusiness.getInstance();

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        long userId = (Long) ((DynamicObject) this.getModel().getValue("personid")).get("id");
        long attfileid = (Long) ((DynamicObject) this.getModel().getValue("attfile")).get("id");
        DynamicObjectCollection entryentity = this.getModel().getEntryEntity("entryentity");

        for (int i = 0; i < entryentity.size(); i++) {
            DynamicObject dynamicObject = entryentity.get(i);
            Date signpoint = dynamicObject.getDate("signpoint");
            Optional<String> supTimes = this.mobSupSignBusiness.getSupTimes(this.getView(), userId, attfileid, (DynamicObject) null, signpoint);
            if (supTimes.isPresent()) {
                this.getModel().setValue("signtimestip", supTimes.get(), i);
            }
        }

    }
}
